#define MSAUTO_MAINTENANCE_C
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
//set start flag
#include <libmscommon/mstime.h>
#include <libmscommon/msreboot.h>
#include <libmslog/mslog.h>

#define FLAG "AUTO_MAINTENANCE"

//send config file
void msautomtc_api_init(RSTime *pRstime,ms_string strRstime)
{
#if defined(OS_LINUX_SOC)
	memset(pRstime,0,sizeof(RSTime));
	mstime_api_parsetimestr2(strRstime, pRstime);
	mstime_api_rstimePrint(pRstime);
#endif	
}
void msautomtc_api_run(RSTime rstime,ms_void (* usrTask)( ms_void))
{
#if defined(OS_LINUX_SOC)
	RSTime rs_cur;
	memset(&rs_cur,0,sizeof(RSTime));
	mstime_api_rstimeGetCur(&rs_cur);
	if( ((0!=rstime.tmyear &&rs_cur.tmyear==rstime.tmyear )||(0==rstime.tmyear)	)
		&&((0!=rstime.tmmon &&rs_cur.tmmon==rstime.tmmon )||(0==rstime.tmmon)	)
		&&((0!=rstime.tmday &&rs_cur.tmday==rstime.tmday )||(0==rstime.tmday)	)
		&&(rs_cur.tmhour==rstime.tmhour )
		&&(rs_cur.tmmin==rstime.tmmin )	){
		if(!(rs_cur.tmsec<rstime.tmsec)
			&&(rs_cur.tmsec<(rstime.tmsec+5))){
			
			usrTask();
			
			ms_api_forceReboot();
		}
	}
#endif
}
#undef MSAUTO_MAINTENANCE_C
